package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;
    /**
     * 获取所有套餐信息
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result getSetmeal(){
        try {
            log.info("查询所有套餐信息成功");
            Result result = new Result();
            result.setFlag(true);
            result.setData(setmealService.getSetmeal());
            result.setMessage(MessageConstant.GET_SETMEAL_LIST_SUCCESS);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询所有套餐信息失败");
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    /**
     * 根据id查询套餐信息
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(@RequestParam Integer id){
        try {
            log.info("查询套餐信息成功");
            Result result = new Result();
            result.setFlag(true);
            result.setData(setmealService.findById(id));
            result.setMessage(MessageConstant.GET_SETMEAL_LIST_SUCCESS);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询套餐信息失败");
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }
}
